<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"import="base.*,pojo.*,service.*,java.util.*,java.text.*,java.io.*,java.awt.*"%>

<%
	request.setCharacterEncoding("utf-8");

		FileDialog file = new FileDialog(new Frame(), "打开", FileDialog.LOAD);//打开目录选择
		file.setVisible(true);
		String dir = file.getDirectory();//文件根目录
		String name = file.getFile();//文件名
		session.getServletContext().getRealPath("/");
		
		InputStream is = new FileInputStream(dir + name);//把选择的文档输入输入流
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
		String date=df.format(new Date());
		String getPath = date.substring(0, 4)+"/"+date.substring(4, 6)+"/"+date.substring(6, 8)+"/";
		String getName= date+".jpg";
		String output = session.getServletContext().getRealPath("/")+getPath;//导出的目录
        response.getWriter().write("{\"success\":true,\"path\":\""+getPath+getName+"\"}");
		File filename = new File(output);//输出目录
		if(!filename.exists()){filename.mkdirs();}
		OutputStream os = new FileOutputStream(new File(output+getName));//输出流
		byte buffer[] = new byte[4 * 1024];
		int len = 0;
		while ((len = is.read(buffer)) != -1) {
			os.write(buffer, 0, len);//输出
		}
		os.flush();//缓冲区的数据强行输出
		os.close();//关闭
		
%>	  

